#include <iostream>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#define PATHNAME "./fifo"

int main()
{
    // 创建管道文件
    mkfifo(PATHNAME, 0666);
    // 打开
    int rfd = open(PATHNAME, O_RDONLY);
    // 读取
    char buff[1024];
    int cnt = 3;
    while (cnt--)
    {
        int x = read(rfd, buff, sizeof(buff));
        buff[x] = 0;
        std::cout << "read : " << buff << std::endl;
    }
    // 关闭
    close(rfd);
    return 0;
}